package pf.springBoot.springBootSSO.controller.YJQuery;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import pf.springBoot.springBootSSO.controller.shares.YJQueryController;
import pf.springBoot.springBootSSO.interceptor.MvcMenuFilter;
import pf.springBoot.springBootSSO.model.SysStatusModel;
import pf.springBoot.springBootSSO.service.BalanceService;
import pf.springBoot.springBootSSO.service.YJQueryService;

@RestController
public class TestController extends YJQueryController//不继承YJQueryController类不能找到视图，暂时不去找原因了
{
    @Autowired
    private BalanceService _balanceService;
    @Autowired
    private YJQueryService yjQueryService;
    /// <summary>
    /// 批量测试页面的js错误
    /// </summary>
    /// <returns></returns>
//    [System.Web.Mvc.AllowAnonymous]
    public ModelAndView TestMultiPageJs() {
        return View();
    }
    @MvcMenuFilter
    @GetMapping("YJQuery/Test/SysStatus")
    public ModelAndView SysStatus()
    {
//        var service = new BalanceService();
    	//YJQueryService yjQueryService = new YJQueryService();
        //var model = new Dictionary<String, bool>//true为正常
        //{
        //    {"分公司记录日志",service.GetDayVisitCount(DateTime.Today)+service.GetDayVisitCount(DateTime.Today.AddDays(-1))>0 }//昨天今天都没写日志就说明有异常
        //};
        String ms = "";
        List<SysStatusModel> model = new ArrayList<SysStatusModel>();//true为正常

        SysStatusModel item = new SysStatusModel();
    	item.ItemName = "分公司记录日志";
    	Calendar yesterday=Calendar.getInstance();
    	yesterday.add(Calendar.DATE, -1);
	    item.Success = _balanceService.GetDayVisitCount(Calendar.getInstance())+_balanceService.GetDayVisitCount(yesterday)>0;
	    //item.ErrorMessage = ms;
	    model.add(item);
//
//benjamin todo
//        SysStatusModel item = new SysStatusModel();
//        	item.ItemName = "Sales是否匹配Orders表";
//        item.Success = service.IsSalesMatchOrders(out ms);
//        item.ErrorMessage = ms;
//        model.Add(item);
//
//         item = new SysStatusModel
//        {
//            ItemName = "旧直销员系统调用crm接口情况"
//        };
//        item.Success = yjQueryService.GetTransErrorLogCount()<1;
//        item.ErrorMessage = item.Success?null:"存在调用失败";
//        model.Add(item);
        return View(model,"Areas/YJQuery/Test/SysStatus");
    }

//    [System.Web.Mvc.AllowAnonymous]
//    public ActionResult TestDisabledField()
//    {
//        ViewData["tgdepList"] = TgMessage.GetTgDep();
//        return View();
//    }
//    [System.Web.Mvc.AllowAnonymous]
//    [HttpPost]
//    public ActionResult PostTestDisabledField(String tgdep)
//    {
//        return base.Json(PFJsonData.SetFault(tgdep));
//    }
}